﻿using System;
using System.Collections.Generic;
using System.Collections;

namespace Gonte.Algorithms
{
    public static class ShellSorter<T> 
        where T : IComparable
    {
        public static void Sort(IList list)
        {
            if (list == null
                || list.Count == 0)
            {
                return;
            }

            int length = list.Count;
            int inc = length / 2;

            while (inc > 0)
            {
                for (int i = inc; i < length; ++i)
                {
                    T temp = (T)list[i];
                    int j = i;

                    while (j >= inc && ((T)list[j - inc]).CompareTo(temp) > 0)
                    {
                        list[j] = list[j - inc];
                        j -= inc;
                    }
                    list[j] = temp;
                }
                inc /= 2;
            }
        }
    }
}
